package game.util;

import edu.monash.fit2099.engine.Actor;
import edu.monash.fit2099.engine.GameMap;
import edu.monash.fit2099.engine.Location;

public class LocationUtil {
//    格式化location字符串
    public static String getLocationPrettyString(Location location){
        String res = "Location ("+location.x()+","+location.y()+") ";
        return  res;
    }

//    计算两点距离
    public static int distance(Location a, Location b) {
        return Math.abs(a.x() - b.x()) + Math.abs(a.y() - b.y());
    }

//计算下一步
    public static Location calNextStep(Location from,Location to){
        GameMap map = to.map();

        int[] step={0,0};
        if(to.x() < from.x()){
            step[0] = -1;
        }else if(to.x() > from.x()){
            step[0] = 1;
        }
        if(to.y() < from.y()){
            step[1] = -1;
        }else if (to.y() > from.y()){
            step[1] = 1;
        }

        Location nextStep = map.at(from.x() + step[0], from.y() + step[1]);
        return nextStep;
    }
}
